package mil.af.amc.adpetracker.util;

import org.apache.struts.action.ActionForward;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

/**
 * Please Fill in this Javadoc
 *
 * @author TSgt Jason Ferguson
 */

public class ForwardParameters {

    private Map params = new HashMap();

    public ForwardParameters add(String paramName, String paramValue) {
        params.put(paramName, paramValue);
        return this;
    }

      /**
      * Add parameters to provided ActionForward
      * @param forward ActionForward to add parameters to
      * @return ActionForward with added parameters to URL
      */
      public ActionForward forward(ActionForward forward){
            StringBuffer path=new StringBuffer(forward.getPath());
            Iterator iter=params.entrySet().iterator();
            if(iter.hasNext()){
               //add first parameter, if avaliable
                  Map.Entry entry=(Map.Entry)iter.next();
                  path.append("?"+entry.getKey()+"="+entry.getValue());
               //add other parameters
                  while(iter.hasNext()){
                        entry=(Map.Entry)iter.next();
                        path.append("&"+entry.getKey()+"="+entry.getValue());
                  }
            }

            return new ActionForward(path.toString());
      }
}
